import { Body,Post,Controller,Inject } from "@midwayjs/core";
import { Context } from "@midwayjs/koa";
import { UserDto,UserLoginDto } from "../dto/userDto";
import { authService } from "../service/auth.service";
import { UserService } from "../service/user.service";
@Controller('/auth')
export class authController {
    @Inject()
    ctx: Context;

    @Inject()
    authService: authService;

    @Inject()
    userService: UserService;

/**
 * @name 注册接口
 * @description Post /auth/register
 * @returns {object} 
 */
@Post('/userRegister')
async register(@Body() userData:UserDto ): Promise<object> {
    const { account, password, name, email, } = userData;
    return await this.authService.register(account, password, name, email);
    }


/**
 * @name 登录接口
 * @description Post /auth/userLogin
 * @returns {object}
 */
@Post('/userLogin')
async Login(@Body()loginData: UserLoginDto){
    const { account, password } = loginData;
    return await this.authService.login(account, password);
    }
}